package com.yisoo.ubag.iot.controller;


import com.yisoo.common.to.CheckDeviceIsOpenTo;
import com.yisoo.common.to.RefreshBagStatusTo;
import com.yisoo.common.utils.R;
import com.yisoo.ubag.iot.service.BoxRelBagService;
import com.yisoo.ubag.iot.service.DevRelOrderService;
import com.yisoo.ubag.iot.service.DeviceService;
import com.yisoo.ubag.iot.service.StatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("iot/feign")
public class FeignController {

    @Autowired
    private DeviceService deviceService;

    @Autowired
    public DevRelOrderService devRelOrderService;

    @Autowired
    BoxRelBagService boxRelBagService;
    @Autowired
    StatusService statusService;


    @GetMapping("/get/bag/up/data/{bagId}")
    RefreshBagStatusTo getBagStatusData(@PathVariable("bagId")Long bagId){
        return statusService.getBagUpStatus(bagId);
    }


    @GetMapping("/check/{devsecret}")
    public CheckDeviceIsOpenTo check(@PathVariable("devsecret") String  devSecret){
        return deviceService.check(devSecret);
    }

    @GetMapping("/open/{bagId}")
    public R open(@PathVariable("bagId") String  bagId){
        return deviceService.open(bagId);
    }
    @GetMapping("/close/{bagId}")
    public R close(@PathVariable("bagId") String  bagId){
        return deviceService.close(bagId);
    }

    @GetMapping("/get/bag/status/{bagId}")
    R getBagStatus(@PathVariable("bagId") String  bagId){
        return devRelOrderService.getBagStatus(bagId);
    }

    @GetMapping("/update/bag/status/{bagId}/{data}")
    R updateBagStatus(@PathVariable("bagId")Long bagId, @PathVariable("data")Integer data){
//        return
        return devRelOrderService.updateBagStatus(bagId,data);
    }
    @GetMapping("/lock/bag/{devcode}/{bagId}")
    R lock(@PathVariable("devcode")String devcode, @PathVariable("bagId")Long bagId)
    {
        return boxRelBagService.lock(devcode,bagId);
    }
//

    @GetMapping("/test/mapping/{bagId}/{control}")
    R testMapping(@PathVariable("bagId")Long bagId, @PathVariable("control")Integer control){
//        return
        return deviceService.testMapping(bagId,control);
    }


//    //仅供测试
//    @GetMapping("/open/test/{devid}")
//    public R openTest(@PathVariable("devid") String  devId){
//        return deviceService.testOpen(devId);
//    }


}
